package cn.cau.epidemicsurveysystem.service.impl;

import cn.cau.epidemicsurveysystem.bean.StaffInfoBean;
import cn.cau.epidemicsurveysystem.dao.StaffInfoRepository;
import cn.cau.epidemicsurveysystem.service.StaffInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffInfoServiceImpl implements StaffInfoService {
    @Autowired
    StaffInfoRepository staffInfoRepository;
    @Override
    public StaffInfoBean findStaffByNo(String staffNo) {
        return staffInfoRepository.findStaffInfoBeanByStaffNo(staffNo);
    }

    @Override
    public StaffInfoBean findStaffById(int staffId) {
        return staffInfoRepository.findStaffInfoBeanByStaffId(staffId);
    }

    @Override
    public List<StaffInfoBean> findall() {
        return staffInfoRepository.findAll();
    }

    @Override
    public List<StaffInfoBean> findStaffInfoBeansByStaffWorkStateAndStaffWorkAreaOrderByStaffNo(int state,String area) {
        return staffInfoRepository.findStaffInfoBeansByStaffWorkStateAndStaffWorkAreaOrderByStaffNo(state,area);
    }

    @Override
    public List<StaffInfoBean> findStaffInfoBeansByStaffWorkStateAndStaffWorkAreaAndStaffPositionOrderByStaffNo(int state, String area, String position) {
        return staffInfoRepository.findStaffInfoBeansByStaffWorkStateAndStaffWorkAreaAndStaffPositionOrderByStaffNo(state,area,position);
    }

    @Override
    public StaffInfoBean save(StaffInfoBean staffInfoBean) {
        return staffInfoRepository.save(staffInfoBean);
    }
    @Override
    public boolean updateStaffInfo(StaffInfoBean staffInfoBean){
        boolean status=false;
        try {
            staffInfoRepository.save(staffInfoBean);
            status=true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return status;
    }


}
